package com.example.reschain.demo02.service;

import com.example.reschain.demo02.OrderContext;
import com.example.reschain.demo02.OrderHandleIntercept;
import org.springframework.stereotype.Component;

@Component
public class RiskOrderHandleInterceptService implements OrderHandleIntercept {

    @Override
    public int sort() {
        return 4;
    }

    @Override
    public OrderContext handle(OrderContext context) {
        System.out.println("进行风控校验：检查用户是否命中黑名单，是否存在异常下单行为");

        // 模拟：如果用户是黑名单，则抛异常中断责任链
        if ("blacklist".equals(context.getUserId())) {
            throw new RuntimeException("用户命中黑名单，禁止下单");
        }

        return context;
    }
}
